<template>
  <div class="flowpath-container">
    <div>
      <div class="mb20">
        <span class="color_494949 ft12 pr5">{{ translate('基站名称') }}：</span>
        <ElInput
          v-model="formInfo.BSName"
          class="w164 mr14"
          placeholder="请输入基站名称"
        />
        <span class="color_494949 ft12 pr5">{{ translate('基站编码') }}：</span>
        <ElInput
          v-model="formInfo.BSID"
          class="w164 mr14"
          :placeholder="translate('请输入基站编码')"
        />
        <el-button class="settingBtn mr10" type="primary" @click="getList">
          {{ translate('查询') }}
        </el-button>
      </div>
      <el-table :data="tableData">
        <el-table-column prop="value" type="selection" width="55" />
        <!-- <el-table-column label="序号" type="index" width="55" /> -->
        <!-- <el-table-column label="编码" prop="ID" show-overflow-tooltip /> -->
        <el-table-column
          :label="translate('基站编码')"
          prop="BSID"
          show-overflow-tooltip
          width="160"
        />
        <el-table-column
          :label="translate('基站名称')"
          show-overflow-tooltip
          width="260"
        >
          <template #default="{ row }">
            <div>
              <span v-if="row.BSID">{{ '[' + row.BSID + ']' }}</span>
              <span v-if="row.BSName">{{ row.BSName }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          :label="translate('密钥')"
          prop="Code"
          show-overflow-tooltip
        />
        <el-table-column
          :label="translate('公司')"
          prop="CompanyName"
          show-overflow-tooltip
        />
        <el-table-column
          :label="translate('版本号')"
          prop="Version"
          show-overflow-tooltip
        />
        <el-table-column
          :label="translate('备注')"
          prop="Remark"
          show-overflow-tooltip
        />
        <el-table-column
          :label="translate('状态')"
          prop="Status"
          show-overflow-tooltip
        >
          <template #default="{ row }">
            <div>
              {{
                row.Status === 1
                  ? translate('正常')
                  : row.Status === 0
                  ? translate('禁用')
                  : translate('未知')
              }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column
          :label="translate('是否开始升级')"
          show-overflow-tooltip
        >
          <template #default="{ row }">
            <div>
              {{ row.BurnRunStatus === 1 ? translate('否') : translate('是') }}
            </div>
          </template>
        </el-table-column> -->
        <!-- <el-table-column
          :label="translate('跳转至APP')"
          prop="JumpAppStatus"
          show-overflow-tooltip
        >
          <template #default="{ row }">
            <div>
              {{ row.JumpAppStatus === 1 ? translate('否') : translate('是') }}
            </div>
          </template>
        </el-table-column> -->
        <el-table-column
          :label="translate('下载文件')"
          prop="DownFileStatus"
          show-overflow-tooltip
        >
          <template #default="{ row }">
            <div>
              {{ row.DownFileStatus === 1 ? translate('否') : translate('是') }}
            </div>
          </template>
        </el-table-column>
        <el-table-column :label="translate('重启')" prop="ReSetStatus">
          <template #default="{ row }">
            <div>
              {{
                row.ReSetStatus === 1 ? translate('已重启') : translate('否')
              }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column
          :label="translate('创建时间')"
          prop="CreateDate"
          show-overflow-tooltip
        /> -->
        <el-table-column :label="translate('连接状态')">
          <template #default="{ row }">
            <div :class="row.Code == '0' ? 'color_l' : 'color_red'">
              <vab-icon :icon="row.Code == '0' ? 'link-m' : 'link-unlink-m'" />
              {{ row.Code == '0' ? translate('已连接') : translate('未连接') }}
            </div>
          </template>
        </el-table-column>
        <el-table-column :label="translate('操作')" width="100">
          <template #default="{ row }">
            <el-button plain size="small" type="primary" @click="detailFn(row)">
              {{ translate('编辑') }}
            </el-button>
            <!-- <el-button plain size="small" type="primary" @click="detailFn(row)">
              {{ translate('设置登录') }}
            </el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <div v-if="total > 0" class="pagination">
        <ElPagination
          background
          :current-page="pageNo"
          :layout="layout"
          :page-size="pageSize"
          :total="total"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </div>
    <el-dialog
      v-model="dialogVisible"
      :title="translate('基站详情')"
      width="600px"
    >
      <detail :form="form" />
      <template #footer>
        <el-button @click="dialogVisible = false">
          {{ translate('取消') }}
        </el-button>
        <el-button type="primary" @click="submit">
          {{ translate('确认') }}
        </el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import { BaseStationData, getbs, editbs } from '@/api/eslstock'
  import { MenuAuth } from '~/src/utils/permission'
  import detail from './components/detail'
  import { translate } from '@/i18n'
  export default defineComponent({
    name: 'Arrival',
    components: { detail },
    data() {
      return {
        tableData: [],
        searchInfo: '',
        total: 0,
        pageNo: 1,
        pageSize: 20,
        dialogVisible: false,
        layout: 'total, sizes, prev, pager, next, jumper',
        form: {},
        formInfo: {
          BSName: '',
          BSID: '',
        },
        translate: translate,
      }
    },
    created() {
      this.MenuAuths = MenuAuth
      this.getList()
    },
    methods: {
      //分页条数切换
      handleSizeChange(val) {
        this.pageSize = val
        this.getList()
      },
      //分页切换
      handleCurrentChange(val) {
        this.pageNo = val
        this.getList()
      },
      detailFn(row) {
        this.getbsData(row)
      },
      async getbsData(val) {
            const params = {
              id: val.ID
            }
            const data = await getbs(params)
            if(data.code === '200') {
              this.form = data.data.data
              console.log(this.form)
              this.dialogVisible = true
            }else {
              this.$message({
                  type: 'error',
                  message: data.message,
                })
            }
      },
      submit() {
        this.editbsSave()
      },
      async editbsSave() {
            const params = this.form
            const data = await editbs(params)
            if(data.code === '200') {
              this.$message({
                  type: 'success',
                  message: '保存成功',
                })
            this.dialogVisible = false
            }else {
              this.$message({
                  type: 'error',
                  message: data.message,
                })
            }
      },
      async getList() {
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            {
              name: 'BSName',
              value: this.formInfo.BSName,
            },
            {
              name: 'BSID',
              value: this.formInfo.BSID,
              displayType: 'like',
            },
          ]),
          export: false,
          value: '',
        }
        const data = await BaseStationData(params)
        this.tableData = data.data.rows
        this.total = data.data.total
        console.log(this.tableData)
      },
    },
  })
</script>
<style lang="scss" scoped>
  .flowpath-container {
    .color_494949 {
      color: #494949;
    }
    .color_l {
      color: #42d885;
    }
    .color_red {
      color: red;
    }

    .w164 {
      width: 164px;
    }

    .mb20 {
      margin-bottom: 20px;
    }

    .mr14 {
      margin-right: 14px;
    }
    .add-box {
      display: inline-block;
      // width: 100px;
      height: 30px;
      line-height: 30px;
      text-align: center;
      border: 1px solid #999;
      border-radius: 3px;
      cursor: pointer;
      padding: 0 10px;
    }
    // .add-box3 {
    //   width: 60px;
    // }
    .pdb10 {
      padding-bottom: 10px;
    }
  }
  .el-table {
    & ::v-deep th.el-table__cell,
    ::v-deep td.el-table__cell {
      // 设置position 使得 子元素不与其产生新的层叠关系
      position: static;
    }
  }
</style>
